using System.Resources;


namespace HappyTemplate
{
	internal enum TemplateErrorCode
	{
		UnexpectedEndOfInput,
		InvalidCharacter_Character_AsciiCode,
		UnexpectedToken_TokenText,
		Expected_Expected_Actual,
		NewLineInLiteralString,
		MultipartIdentiferNotAllowedInThisContext,
		DuplicateInputValue_Value,
		DefaultValueMayOnlyBeSpecifiedOnce,
		UnexpectedEndOfInputWhileParsingSection,
		InvalidEscapeSequence_InvalidCharacter,
		LiteralCharsMustBeOneCharLong	
	}

	internal class TemplateErrorCollector : ErrorCollectorBase
	{
		public TemplateErrorCollector(SourceErrorCollection sourceErrors) : base(sourceErrors) { }

		protected override ResourceManager MessageResourceManager { get { return Resources.TemplateErrorMessages.ResourceManager; }}

		internal void AddUnexpectedEndOfInput(SourceLocation loc)
		{
			base.Add(loc, TemplateErrorCode.UnexpectedEndOfInput.ToString());
		}

		public void AddInvalidCharacter(SourceLocation location, char c)
		{
			base.Add(location, TemplateErrorCode.InvalidCharacter_Character_AsciiCode.ToString(), c, (ushort)c);
		}

		public void AddUnexpectedToken(Token t) 
		{
			base.Add(t.Location, TemplateErrorCode.UnexpectedToken_TokenText.ToString(), t.Text);
		}

		public void AddExpected(string expected, Token actual)
		{
			base.Add(actual.Location, TemplateErrorCode.Expected_Expected_Actual.ToString(), expected, actual.Text);
		}

		public void AddNewLineInStringLiteral(SourceLocation location)
		{
			base.Add(location, TemplateErrorCode.NewLineInLiteralString.ToString());
		}

		public void AddMultipartIdentifierNotAllowedInThisContext(SourceLocation location)
		{
			base.Add(location, TemplateErrorCode.MultipartIdentiferNotAllowedInThisContext.ToString());
		}

		public void AddDuplicateInputValue(Token value)
		{
			base.Add(value.Location, TemplateErrorCode.DuplicateInputValue_Value.ToString(), value.Text);
		}

		public void AddDefaultValueMayOnlyBeSpecifiedOnce(SourceLocation location) 
		{
			base.Add(location, TemplateErrorCode.DefaultValueMayOnlyBeSpecifiedOnce.ToString());
		}


		public void AddUnexpectedEndOfInputWhileParsingSection(SourceLocation location) 
		{
			base.Add(location, TemplateErrorCode.UnexpectedEndOfInputWhileParsingSection.ToString());
		}	

		public void AddInvalidEscapeSequence(SourceLocation location, char invalidChar)
		{
			base.Add(location, TemplateErrorCode.InvalidEscapeSequence_InvalidCharacter.ToString(), invalidChar);
		}

		public void AddLiteralCharsMustBeOneCharLong(SourceLocation location)
		{
			base.Add(location, TemplateErrorCode.LiteralCharsMustBeOneCharLong.ToString());
		}
	}
}
